﻿//#define _CRT_SECURE_NO_WARNINGS
// C/C++ (Clang) 官网 https://legacy.cplusplus.com
// C/C++ (GCC) 官网 https://zh.cppreference.com/w/cpp
// C/C++ (Visual Studio) 官网 https://learn.microsoft.com/zh-cn/cpp/cpp/?view=msvc-170
// OpenGl 官网 https://docs.gl/
#include "common.h"

#include "MusicPlayer.h"
#include <stdexcept>


void MusicPlayer::init_SoundTouch()
{
    soundTouch.setSampleRate(my_ffmpeg->st_out_sample_rate);
    soundTouch.setChannels(my_ffmpeg->st_stereo_layout.nb_channels);

    // 初始化 SoundTouch 参数
    soundTouch.setTempo(TEMPO);
    soundTouch.setPitch(PITCH);
    soundTouch.setRate(RATE);
}

void MusicPlayer::set_audio_pitch(float pitch)
{
    if (pitch >= 0.01f && pitch <= 3.00f) {
        soundTouch.setPitch(PITCH = pitch);
    }
    else {
        qDebug() << "pitch must be greater than or equal to 0.01 and less than or equal to 3.00";
    }
}

void MusicPlayer::set_audio_rate(float rate)
{
    if (rate >= 0.01f && rate <= 2.00f) {
        soundTouch.setRate(RATE = rate);
    }
    else {
        qDebug() << "rate must be greater than or equal to 0.01 and less than or equal to 2.00";
    }
}

void MusicPlayer::reset_p_swr_context_SoundTouch(
    AVChannelLayout st_layout,
    int st_sample_rate,
    AVSampleFormat st_sample_fmt)
{
    my_ffmpeg->reset_audio_sampler_SoundTouch(st_layout,
                                              st_sample_rate,
                                              st_sample_fmt);
}
